package com.transcasafe.eanpay.example.notify;

import com.alibaba.fastjson.JSONObject;
import com.transcasafe.eanpay.core.http.PayConstant;
import com.transcasafe.eanpay.core.service.model.NotifyMchRequestBody;
import com.transcasafe.eanpay.core.service.model.OrderStatusEnum;
import com.transcasafe.eanpay.core.util.ShaUtil;

import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

/**
 * 通知回调测试
 * 用户未支付没有回调通知，只有支付成功或者失败才会回调通知
 */
public class NotifyTest {

    private static final String MCH_NO = "3820289";
    private static final String MCH_KEY = "123123";

    public static void main(String[] args) {
        NotifyMchRequestBody requestBody = NotifyMchRequestBody.builder()
                .mchNo(MCH_NO)
                .currency("EUR")
                .amount(new BigDecimal("125.00"))
                .orderNo("CP20250904100650358IZNXSU")
                .mchOrderNo("923")
                .status(OrderStatusEnum.SUCCESS.getValue())
                .payType("READIES")
                .build();
        String bodyString = JSONObject.toJSONString(requestBody);
        String timestamp = "1756962041";
        String nonce = "KgYc5kxg7DcFE3qvC4VgqRB9OJANBkia";
        String signatureContent = MCH_NO + "," + timestamp + "," + nonce + "," + bodyString;
        String signature = ShaUtil.getSha256HexString((signatureContent + "," + MCH_KEY).getBytes(StandardCharsets.UTF_8));
        System.out.println(PayConstant.HTTP_HEADER_MCH_NO + ": " + MCH_NO);
        System.out.println(PayConstant.HTTP_HEADER_TIMESTAMP + ": " + timestamp);
        System.out.println(PayConstant.HTTP_HEADER_NONCE + ": " + nonce);
        System.out.println(PayConstant.HTTP_HEADER_SIGNATURE + ": " + "algorithm=SHA-256,version=v1,signature=" + signature);

        System.out.println(bodyString);
    }
}
